/**
 * @author Andrey Anisimov <hercules@inbox.ru>
 */

import core.effect.TimerEffect;

class Tween extends TimerEffect {

    /**
     * @param duration {int} Effect duration, in milliseconds.
     * @param timer {core.util.Timer} Effect timer.
     * @param begin {Number} Start position value.
     * @param end {Number} End position value.
     * @param easing {core.effect.easing.*} Easing effect.
     * @param easingType {String} (optional) Easing type (default is Tween.EASE_IN).
     * @constructor
     */
    this.Tween = function (duration, timer, begin, end, easing, easingType) {
        super(duration, timer);
        this.begin = begin;
        this.end = end;
        this.easing = easing;
        this.easingType = easingType || Tween.EASE_IN;
        this.state = Tween.STATE_READY;
    };

    /**
     * Sets the start position value.
     *
     * @param begin {Number} Start position value.
     */
    this.setStartPosition = function (begin) {
        this.begin = begin;
    };

    /**
     * Returns the start position value.
     *
     * @return Number
     */
    this.getStartPosition = function () {
        return this.begin;
    };

    /**
     * Sets the end position value.
     *
     * @param end {Number} End position value.
     */
    this.setEndPosition = function (end) {
        this.end = end;
    };

    /**
     * Returns the end position value.
     *
     * @return Number
     */
    this.getEndPosition = function () {
        return this.end;
    };

    /**
     * Returns the current position value.
     *
     * @return Number
     */
    this.getPosition = function () {
        return this.easing[this.easingType](this.getTime(), this.begin,
            this.end - this.begin, this.getDuration());
    };

    /**
     * Sets the easing type for the effect.
     *
     * @param easing {core.effect.easing.Easing} The easing object to set.
     */
    this.setEasing = function (easing) {
        this.easing = easing;
    };

    /**
     * Returns the easing type for the tween.
     *
     * @return Easing
     */
    this.getEasing = function () {
        return this.easing;
    };

    /**
     * Sets the easing type.
     *
     * @param type {String} Easing type.
     */
    this.setEasingType = function (type) {
        this.easingType = type;
    };

    /**
     * Returns the easing type.
     *
     * @return String
     */
    this.getEasingType = function () {
        return this.easingType;
    };

    /**
     * Starts the ease in effect.
     */
    this.easeIn = function () {
        this.easingType = Tween.EASE_IN;
        this.play();
    };

    /**
     * Starts the ease out effect.
     */
    this.easeOut = function () {
        this.easingType = Tween.EASE_OUT;
        this.play();
    };

    /**
     * Starts the ease in out effect.
     */
    this.easeInOut = function () {
        this.easingType = Tween.EASE_IN_OUT;
        this.play();
    };

    /**
     * Starts the effect without easing.
     */
    this.easeNone = function () {
        this.easingType = Tween.EASE_NONE;
        this.play();
    };
}

Tween.EASE_NONE = 'easeNone';
Tween.EASE_IN = 'easeIn';
Tween.EASE_OUT = 'easeOut';
Tween.EASE_IN_OUT = 'easeInOut';